﻿using LowCodePlatform.CreateUpdateDto.RBAC;
using LowCodePlatform.Dto.RBAC;
using LowCodePlatform.IRepository.RBAC;
using LowCodePlatform.IRepositorys;
using LowCodePlatform.Model.Rbac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;

namespace LowCodePlatform.Service
{
    public class MyUserService : CrudAppService<UserModel, UserDto, Guid, PagedAndSortedResultRequestDto, CreateUpdateUserDto>, IUserService
    {
        private readonly IRepository<UserModel, Guid> _userInfos;
        public MyUserService(IRepository<UserModel, Guid> user,IRepository<UserModel, Guid> users) : base(user)
        {
            _userInfos = users;
        }
        /// <summary>
        /// //用户信息返填
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        [HttpGet, Route("Edituser")]
        public async Task<UserInfoShowDTO> Edituser(int uid)
        {
            var list = await _userInfos.GetListAsync();
            var slis = list.Where(x => x.Id == uid).FirstOrDefault();
            var rlist = new UserInfoShowDTO();
            rlist.Id = slis.Id;
            rlist.UserName = slis.UserName;
            rlist.LoginName = slis.LoginName;
            rlist.Sex = slis.Sex;
            rlist.UserStata = slis.UserStata;
            rlist.UserCreateTime = slis.UserCreateTime;
            return rlist;
        }

        /// <summary>
        /// 验证密码
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="upwd"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("VerifyPwd")]
        public async Task<int> VerifyPwd(int uid, string upwd)
        {
            var onelist = await _userInfos.GetListAsync();
            var list = onelist.Where(x => x.Id == uid).FirstOrDefault();
            if (list.LoginPwd == upwd)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="useruppwd"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("UpPwd")]
        public async Task<int> UpPwd(UserInfoShowDTO useruppwd)
        {
            var list = ObjectMapper.Map<UserInfoShowDTO, UserInfo>(useruppwd);
            var onelist = await _userInfos.UpdateAsync(list);
            if (onelist != null)
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }
}
